package leetcodecompetition.D346;

public class T6439 {
    public int minLength(String s) {
        StringBuffer stringBuffer = new StringBuffer(s);
        int n = s.length();
        boolean b=false;
        while (!b) {
            b=true;
            for (int i = 0; i < stringBuffer.length() - 1; i++) {
                char c = stringBuffer.charAt(i);
                if (c == 'A') {
                    if (stringBuffer.charAt(i + 1) == 'B') {
                        stringBuffer.delete(i, i + 2);
                        i--;
                        b=false;
                    }
                }
                if (c == 'C') {
                    if (stringBuffer.charAt(i + 1) == 'D') {
                        stringBuffer.delete(i, i + 2);
                        i--;
                        b=false;
                    }
                }
            }
        }

        return stringBuffer.length();
    }
}
